<div class="content">
	<div class="n-row">&nbsp;</div>
	<?=n_mod('nrule')->topNav('权限设置',"规则授权")?>

	<style type="text/css">
	td {cursor: pointer;}
	.nrules-used{color: green}
	.nrules{color: thistle}
	</style>

	<table id="nrules-site" class="a-table a-table-striped">
		<thead>
		<tr>
				<th><?=$data['rule']?></th>
		</tr>
		</thead>
		<tbody>
			<?php
			if(!empty($data['site'])){
				foreach($data['site'] as $key=>$val){
					$str = $key.'-'.$data['pevent'].'-'.$data['libid'];
					$rule_rw = empty($val['rule_rw'])?array():explode(',', $val['rule_rw']);
			?>
			<tr><th><?=$val['name']?>(<?=$key?>)</th>
			<?php
					if (in_array($data['libid'], $rule_rw)) {
						$str .= '-d';
			?>
					<td class="nrules-used" vl="<?=$str?>">授权</td>
			<?php
					}else{
						$str .= '-a';
			?>
					<td class="nrules" vl="<?=$str?>">授权</td>
			<?php
					}
			?>
					</tr>
			<?php
				}
			}else{
			?>
		    <tr>
				<td colspan="2">
				暂无数据
				</td>
		    </tr>
			<?php
			}
			?>
		</tbody>
		<tfoot>
		  <tr><th colspan="2">&nbsp;</th></tr>
		</tfoot>
	</table>
	<a href="<?=n_url('libmg','index')?>" target="_blank" style="float:right;">关联</a>
	<script>
	$(document).ready(function(){
		$('#nrules-site tbody tr td').click(function(){
			var q = $(this).attr('vl');
			var obj = $(this);
			var arr = q.split('-');

			$.post('/nsite/nruleRWToggle.html',{'qurey':q},function(data){
					if (data.state == false) return false;
					if (arr[3] == 'd') {
						obj.removeClass('nrules-used').addClass('nrules');
						var nq = q.replace('-d','-a');
						obj.attr('vl',nq);
					}else{
						obj.removeClass('nrules').addClass('nrules-used');
						var nq = q.replace('-a','-d');
						obj.attr('vl',nq);
					}
			});

		});
	});

	</script>
</div>